<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
   <!-- import Vue before Element -->
  <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <!-- import JavaScript -->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>


</head>

<body>
  <div id="id1">
  	<el-upload
            name="multipartfiles"
  class="upload-demo"
  ref="upload"
  action="http://localhost:9000/cms/rating/savePic"
  :on-preview="handlePreview"
  :on-remove="handleRemove"
  :file-list="fileList"
  :before-upload="beforeUpload"
  :auto-upload="false">
  <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
</el-upload>
</div>

<div>
  <form action="/cms/rating/savePic">
    <input type="button" onclick="submit()" value="Test">
  </form>
</div>

</body>

<script>
  new Vue ({
  		el: '#id1',
    data() {
      return {
        fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
      };
    },
    methods: {
      submitUpload() {
      	console.log("ok")
        this.$refs.upload.submit();
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
      beforeUpload(file){
    var fd = new FormData();
    fd.append('file',file);//传文件

          console.log(fd)
          var config = {	    headers:{'Content-Type':'multipart/form-data'}	};
    //fd.append('srid',this.aqForm.srid);//传其他参数
    axios.post('/cms/rating/savePic',fd).then(function(res){
            alert('成功');
    })
         /* $.ajax({
              type: "POST",
              url: "/cms/rating/savePic",
              processData: false,
              contentType: false,
              async: false,
              data: fd,

              success: function(data){
                  alert('成功');
              }
          });*/
          return true;
}
    }
    
    
  });
  function submit() {
      $.ajax({
          type: "POST",
          url: "/cms/rating/savePic",

          data: "ok",

          success: function(data){
              alert('成功');
          }
      });

  }
  
</script>
 
  
</html>